using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using System.Data.SqlClient;
using SpringWaterDataAccess;

namespace client
{
    /// <summary>
    /// Summary description for bloggerarticles.
    /// </summary>
    public partial class bloggerarticles : System.Web.UI.Page
    {

        protected int userID = 0; 

        protected void Page_Load(object sender, System.EventArgs e)
        {
            userID = Convert.ToUInt16(Request.QueryString["UserID"]);
            // Put user code to initialize the page here
            if (!IsPostBack) 
            {
                ForumDataAccess da = new ForumDataAccess();
                DataTable  dt = da.GetForumCategories(11).Tables[0];
                                
                DropDownList2.DataSource =dt;
                DropDownList2.DataTextField = "CategoryName";
                DropDownList2.DataValueField = "CategoryID";
                DropDownList2.SelectedValue = "44";
                DropDownList2.DataBind();
                
                BindData();         		
            }
        }

        private void BindData() 
        {
            ForumDataAccess da = new ForumDataAccess();
            int totalRecords = 0;
            int rows  = Convert.ToUInt16(DropDownList1.SelectedValue);
            int catID = Convert.ToUInt16(DropDownList2.SelectedValue);
            string Status = Dropdownlist3.SelectedValue;
            
            DataSet ds = da.getPosts(userID,0,0,0,1,rows,out totalRecords,"blog",Status,catID,"CreateDate desc");

            MyRepeater.DataSource = ds;
            MyRepeater.DataBind();
        }

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {    

        }
        #endregion


        protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
        {

            BindData();
        }


        protected void DropDownList2_SelectedIndexChanged1(object sender, EventArgs e)
        {

            BindData();
        }

        protected void Dropdownlist3_SelectedIndexChanged1(object sender, EventArgs e)
        {
                   
            BindData();        
        }


       
        protected void Button1_Click1(object sender, EventArgs e)
        {
            Response.Redirect("bloggerhome.aspx?userID=" + userID);
        }

        protected void Button3_Click1(object sender, EventArgs e)
        {
            Response.Redirect("bloggerarticles.aspx?userID=" + userID);
        }

        protected void Button2_Click1(object sender, EventArgs e)
        {
            Response.Redirect("bloggerinput.aspx?userID=" + userID);
        }

        protected void Button4_Click1(object sender, EventArgs e)
        {
            Response.Redirect("bloggercomments.aspx?userID=" + userID);
        }

        protected void Button5_Click1(object sender, EventArgs e)
        {
            foreach (RepeaterItem myitem in MyRepeater.Items)
            {
                foreach (Control c in myitem.Controls)
                {
                    if (c is CheckBox)
                    {
                        CheckBox cb = (CheckBox)c;

                        if ((cb.Checked))
                        {
                            // Each row has a invisible Label for dispalying word ID
                            Label idLabel = (Label)myitem.FindControl("Label1");

                            if (idLabel != null)
                            {
                                //Response.Write(idLabel.Text + "<br>");
                                ForumDataAccess da = new ForumDataAccess();
                                da.DeletePost(Convert.ToInt16(idLabel.Text));
                            }
                        }
                    }
                }
            }
            BindData();
        }


       

    }
}
